from flask_marshmallow import base_fields
from flask_restplus_patched import ModelSchema
from app.modules.common.schemas import BaseSchema

from .models import User


class BaseUsersSchema(ModelSchema):
    class Meta:
        model = User
        fields = (
            User.id.key,
            User.account.key,
            User.realname.key,
            User.zt_user_id.key,
            User.zt_user_account.key,
            User.email.key,
        )

        dump_only = (
            User.id.key,
        )


class UserListSchema(ModelSchema):
    role_list = base_fields.Nested(
        'BaseRoleSchema',
        many = True
    )

    class Meta(BaseUsersSchema.Meta):
        fields = BaseUsersSchema.Meta.fields + (
            "role_list", "login_ip",
        )


class UserSchema(BaseSchema):
    data = base_fields.Nested(
        UserListSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )
